﻿@using admin.Model
@{
    ViewData["Title"] = "Information";
    Layout = "~/Views/Shared/_MainLayout.cshtml";
    var admin = Model as Administrator;

}


<div class="header">

    <h1 class="page-title">个人信息</h1>
</div>

<ul class="breadcrumb">
    <li><a asp-action="Home">首页</a> <span class="divider">/</span></li>
    <li><a>我的信息</a> <span class="divider">/</span></li>
</ul>

<div class="container-fluid">
    <div class="row-fluid">

        
        <div class="well">
            <ul class="nav nav-tabs">
                <li class="active"><a href="#home" data-toggle="tab">基本信息</a></li>
                <li><a href="#profile" data-toggle="tab">修改密码</a></li>
            </ul>
            <div id="myTabContent" class="tab-content">
                <div class="tab-pane active in" id="home">
                    <form id="tab" method="post" asp-action="SaveInformation">
                        <label>登录ID</label>
                        <input type="text" name="adminID" value="@admin.Id" class="input-xlarge" readonly="readonly">
                        <label>用户名</label>
                        <input type="text" name="adminName" value="@admin.Name" class="input-xlarge auth1"><span class="my-error" id="nname-error">*名字不能为空</span>
                        <label>电话</label>
                        <input type="text" name="adminPhone" value="@admin.Phone" class="input-xlarge auth1" maxlength="11"><span class="my-error" id="nphone-error">*电话格式不正确</span>
                        <div class="btn-toolbar">
                            <button class="btn btn-primary"  id="save-button"  type="submit"><i class="icon-save"></i>保存</button>
                            <button class="btn btn-primary" asp-action="Home" ><i class="icon-backward"></i>返回</button>
                        </div>
                    </form>
                </div>
                <div class="tab-pane fade" id="profile">
                    <form id="tab2" method="post" asp-action="ChangePassword">
                        <label>原密码</label>
                        <input type="password" name="oldPassword" placeholder="请输入原密码" class="input-xlarge auth"><span class="my-error" id="op-error">*原密码不能为空</span>
                        <label>新密码</label>
                        <input type="password" name="newPassword" placeholder="请输入新密码"class="input-xlarge auth"><span class="my-error" id="np-error">*新密码不能为空</span>
                        <label>确认密码</label>
                        <input type="password" name="renewPassword" placeholder="确认密码"class="input-xlarge auth"><span class="my-error" id="rnp-error">*两次密码不一致</span>
                        <div>
                            <button  class="btn btn-primary" id="tab2submit"  type="submit">提交修改</button>
                            <button class="btn btn-primary" href="#myModal"  data-toggle="modal" type="reset">重置密码</button>
                        </div>
                    </form>
                </div>
            </div>

        </div>

        <div class="modal small hide fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h3 id="myModalLabel">密码重置成功</h3>
            </div>
            <div class="modal-body">

                <p class="error-text"><i class="icon-lemon modal-icon"></i>密码已重置为"12345"</p>
            </div>
            <div class="modal-footer">
                <button class="btn btn-danger" data-dismiss="modal">确定</button>
            </div>
        </div>

        <div class="modal small hide fade" id="save-Modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h3 id="myModalLabel">信息保存成功</h3>
            </div>
            <div class="modal-body">

                <p class="error-text"><i class="icon-lemon modal-icon"></i>个人信息已保存</p>
            </div>
            <div class="modal-footer">
                <button class="btn btn-danger" data-dismiss="modal">确定</button>
            </div>
        </div>


    </div>
</div>


<script type="text/javascript">

    $('auth').data({ 's': 0 });

    $('input[name = oldPassword]').blur(function () {
        val = this.value;
        if (val.length == 0) {

            $("#op-error").show();
            $(this).data({ 's': '0' })
        }
        else {
            $("#op-error").hide();
            $(this).data({ 's': '1' })
        }
    });


    $('input[name = newPassword]').blur(function () {
        val = this.value;
        if (val.length == 0) {

            $("#np-error").show();
            $(this).data({ 's': '0' })
        }
        else {
            $("#np-error").hide();
            $(this).data({ 's': '1' })
        }
    });

    $('input[name = renewPassword]').blur(function () {
        val1 = this.value;
        $('input[name = newPassword]').blur(function () {
            val2 = this.value;
        });
        if (val1 != val2 ){

            $("#rnp-error").show();
            $(this).data({ 's': '0' })
        }
        else {
            $("#rnp-error").hide();
            $(this).data({ 's': '1' })
        }
    });


    $('#tab2').submit(function () {
        $('.auth').blur();
        tot = 0;
        $('.auth').each(function () {
            if ($(this).data('s') == 1) {
                tot += 1;
            }
        });
        if (tot < 3) {
            return false;    
        }
        
    });


    $('auth1').data({ 's': 0 });

    $('input[name = adminName]').blur(function () {
        val = this.value;
        if (val.length == 0) {

            $("#nname-error").show();
            $(this).data({ 's': '0' })
        }
        else {
            $("#nname-error").hide();
            $(this).data({ 's': '1' })
        }
    });


    $('input[name = adminPhone]').blur(function () {
        val = this.value;
        if (val.match(/^1[3|4|5|8]\d{9}$/)) { 
            $("#nphone-error").hide();
            $(this).data({ 's': '1' })
        }
        else {
            $("#nphone-error").show();
            $(this).data({ 's': '0' })
        }
    });


    $('#tab').submit(function () {
        $('.auth1').blur();
        tot = 0;
        $('.auth1').each(function () {
            if ($(this).data('s') == 1) {
                tot += 1;
            }
        });
        if (tot < 2) {
            return false;
        }
    });

</script>


